<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发布新投票</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="http://47.106.66.89:8080/js/vue.min.js"></script>
	<script src="http://47.106.66.89:8080/js/axios.min.js"></script>
	<link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
	<script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
	<script src="/js/vote.js"></script>
</head>
<body>
<div id="app">
	<vote>
		<div id="voteManage" class="box">
			<h2>添加新投票</h2>
			<div class="content">
				<form method="post" action="view.html">
					<dl>
						<dt>投票内容：</dt>
						<dd>
							<input type="hidden" name="entityId" value=""/>
							<input type="text" class="input-text" v-model="vote.vname"  value=""/>
						</dd>
						<dt>投票类型：</dt>
						<dd>
							<input type="radio" v-model="vote.vtype" value="单选" />单选
							<input type="radio" v-model="vote.vtype" value="多选" />多选
						</dd>
						<dt>投票选项：</dt>

						<dd id="voteoptions">
<!--							vue 绑定数组内部元素, 要使用下标绑定-->
							<p v-for=" item,idx in vote.items ">
								<input type="text" class="input-text"
									   v-model="vote.items[idx].iname" />
							</p>
						</dd>


						<dt></dt>
						<dd class="button">
							<input @click.prevent="commit" type="image" src="images/button_submit.gif" />
							<a href="#" @click.prevent="vote.items.push({iname:''})">增加选项</a>
							<a href="index.html" @click.prevent="vote.items.pop()">取消操作</a>
						</dd>
					</dl>
				</form>
			</div>
		</div>
	</vote>
</div>
<script>
	var v = new Vue({
		el : "#app",
		data : {
			vote:{
				vname:"",
				vtype:"单选",
				items:[{iname:""},{iname:""}]
			}
		},
		created() {
		},
		methods : {
			commit(){
				axios.post("/vote/vote/create", this.vote).then(res=>{
					if(res.data.code == 1){
						location.href = "/index.html";
					} else {
						this.$alert(res.data.msg);
					}
				});
			}
		}
	})
</script>

</body>
</html>

